<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">信号源管理</h1>
</div>


<div class="wrapper-md"  >
<div class="panel panel-default">
  <div ng-controller="infoEditCtrl">
    <div class="row">
    
      <div class="col-sm-12" >
        <form name="form-contact" ng-submit="processForm()" class="form-horizontal">

            <div class="panel-heading">
              <span class="h4">

<button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>


              </span>
            </div>
            <div class="panel-body">
            

              

 <div class="panel-heading">
              <span class="h4" style="color: blue;">信号源简介信息</span>
            </div>

              <div class="form-group">
    <label class="col-sm-1 control-label">信号源分类</label>
    <div class="col-sm-5">
<ui-select multiple ng-model="multipleDemo.selectedPeopleWithGroupBy" theme="bootstrap" ng-disabled="disabled">
            <ui-select-match placeholder="信号源分类">{{$item.ClassName}} &lt;{{$item.ClassRemark}}&gt;</ui-select-match>
           
            <ui-select-choices  repeat="person in people | propsFilter: {ClassName: $select.search, Id: $select.search}">
              <div ng-bind-html="person.ClassName | highlight: $select.search"></div>
              <small>
            
                编号: <span ng-bind-html="''+person.Id | highlight: $select.search"></span>
              </small>
            </ui-select-choices>
          </ui-select>
    </div>

    <label  class="col-sm-1 control-label"></label>
    <div class="col-sm-5">

    </div>
  </div>


<div class="form-group">
    <label class="col-sm-1 control-label">名称</label>
    <div class="col-sm-5">
 <input type="text" class="form-control" placeholder="信号源名称" ng-model="contact.SignalName" required >
    </div>

    <label  class="col-sm-1 control-label">长名称</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" placeholder="信号源长名称" ng-model="contact.SignalLongName" required >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


<div class="form-group">
    <label class="col-sm-1 control-label">视频帧率fps</label>
    <div class="col-sm-5">
 <input type="number" class="form-control" placeholder="视频帧率" ng-model="contact.VideoFrameRate"   min="0" max="99999"  required  >
    </div>

    <label  class="col-sm-1 control-label">比特率bps</label>
    <div class="col-sm-5">
      <input type="number" min="0" max="99999" class="form-control" placeholder="比特率" ng-model="contact.VideoBitRate"  >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>




<div class="form-group">
    <label class="col-sm-1 control-label">信号传输模式</label>
    <div class="col-sm-5">
       <select class="form-control " ng-model="contact.SignalTransMode" required >
  <option ng-repeat="x in signalTransModes" value="{{x.key}}">{{x.value}}</option>
                
      </select>
    </div>

   
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>











<div class="form-group">
    <label class="col-sm-1 control-label">信号源URL</label>
    <div class="col-sm-5">
 <input type="text" class="form-control" placeholder="信号源URL" ng-model="contact.SignalUrl" required >
    </div>

    <label  class="col-sm-1 control-label">信号源URL推模式</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" placeholder="信号源URL推模式" ng-model="contact.SignalPushUrl"  >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


<div class="form-group">
    <label class="col-sm-1 control-label">视频编码</label>
    <div class="col-sm-5">
 <input type="text" class="form-control" placeholder="视频编码" ng-model="contact.VideoCodec" required >
    </div>

    <label  class="col-sm-1 control-label">显示比例</label>
    <div class="col-sm-5">
  <select class="form-control " ng-model="contact.SignalDar"  >
                      <option ng-repeat="x in signalDars" value="{{x.key}}">{{x.value}}</option>
                
                  </select>


    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

<div class="form-group">
    <label class="col-sm-1 control-label">视频宽度</label>
    <div class="col-sm-5">
 <input type="number" min="0" max="99999" class="form-control" placeholder="视频宽度" ng-model="contact.VideoWidth"  >
    </div>

    <label  class="col-sm-1 control-label">视频高度</label>
    <div class="col-sm-5">
      <input type="number" min="0" max="99999" class="form-control" placeholder="视频高度" ng-model="contact.VideoHeight"  >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

  <div class="form-group">
    <label class="col-sm-1 control-label">音频声道</label>
    <div class="col-sm-5">
  <select class="form-control " ng-model="contact.AudioChannel"  >
                      <option ng-repeat="x in audioChannels" value="{{x.key}}">{{x.value}}</option>
                
                  </select>


    </div>

    <label  class="col-sm-1 control-label">音频编码</label>
    <div class="col-sm-5">
    <select class="form-control " ng-model="contact.AudioCodec"  >
                      <option ng-repeat="x in audioCodecs" value="{{x.key}}">{{x.value}}</option>
                
                  </select>

    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

   <div class="form-group">
    <label class="col-sm-1 control-label">音频采样率</label>
    <div class="col-sm-5">
 <input type="number" min="0" max="99999" class="form-control" placeholder="音频采样率" ng-model="contact.AudioSamplingRate" required >
    </div>

    <label  class="col-sm-1 control-label">音频流比特率</label>
    <div class="col-sm-5">
      <input type="number" min="0" max="99999" class="form-control" placeholder="音频流比特率" ng-model="contact.AudioBitRate"  >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


              <div class="form-group">
                 <label class="col-sm-1 control-label">备注</label>  
               <div class="col-sm-10">
                   <textarea class="form-control" ng-model="contact.SignalRemark" rows="6" placeholder="备注"></textarea>
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>




  
    <div class="form-group">
                 <label class="col-sm-1 control-label">小图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.SignalSmallImage" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

      <div class="form-group">
                 <label class="col-sm-1 control-label">中图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.SignalMediumImage" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


      <div class="form-group">
                 <label class="col-sm-1 control-label">大图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.SignalLargeImage" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

            </div>

        

                 <div class="panel-body">

  
           
 <div class="panel-heading">
              <span class="h4" style="color: blue;">配置信息</span>
            </div>



   <div class="form-group">
    <label class="col-sm-1 control-label">启用/停用</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
                 <input type="checkbox" ng-model="signalEnable" checked>
              <i></i>
            </label>
    </div>

   
     <label class="col-sm-1 control-label">PC</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
 <input type="checkbox" ng-model="signalDisplayOnPc" checked>
              <i></i>
            </label>
    </div>
     <label class="col-sm-1 control-label">Phone</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
 <input type="checkbox" ng-model="signalDisplayOnPhone" checked>
              <i></i>
            </label>
    </div>


 <label class="col-sm-1 control-label">Pad</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox" ng-model="signalDisplayOnPad" checked>

              <i></i>
            </label>
    </div>

     <label class="col-sm-1 control-label">TV</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox" ng-model="signalDisplayOnTv" checked>
              <i></i>
            </label>
    </div>


  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>



  <!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="contact.SignalUuid"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'" >
    <!--隐藏字段-->


            </div>


            <footer class="panel-footer text-right bg-light lter">
              <button type="submit" class="btn btn-success">提交</button>
            </footer>
          </div>
        </form>
      </div>
    </div>
   
</div>
</div>




</div>


<!--angularjs-->
<script type="text/javascript">
  'use strict';
app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {




  $scope.signalEnable = true;
  $scope.signalDisplayOnPc = true;
  $scope.signalDisplayOnPad = true;
  $scope.signalDisplayOnPhone = true;
  $scope.signalDisplayOnTv = true;






 $scope.signalTransModes = [
    {key : "push", value : "推模式"},
    {key : "pull", value : "拉模式"}
  ];

 $scope.videoCodecs = [
    {key : "H.264", value : "H.264"},
    {key : "H.265", value : "H.265"}
  ];

 $scope.signalDars = [
    {key : "4:3", value : "4:3"},
    {key : "16:9", value : "16:9"},
    {key : "21:9", value : "21:9"}
  ];
 $scope.audioChannels = [
    {key : "1", value : "1"},
    {key : "2", value : "2"},
    {key : "5.1", value : "5.1"}
  ];
 $scope.audioCodecs = [
    {key : "AAC", value : "AAC"},
    {key : "MP3", value : "MP3"}
  ];







//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.back();
    };
//返回按钮：结束

   var infoId = $stateParams.infoId;
    console.log('获取路由参数infoId：'+infoId);


 //如果infoId不为空，查询详情：开始
  if(''!=infoId){
      var getInfoUrl = API_URL+"signal_info?query=delflag:0,id:"+infoId+"&sortby=updateTime&order=desc"    

    $http.get(getInfoUrl).success(function (response) {
         var obj = response[0];

        obj.VideoFrameRate = Number(obj.VideoFrameRate);

    if("0" == obj.UserEnable){
          $scope.userEnable = false;
         }

    if("0" == obj.SignalEnable){
          $scope.signalEnable = false;
         }
    if("0" == obj.SignalDisplayOnPc){
          $scope.signalDisplayOnPc = false;
         }
    if("0" == obj.SignalDisplayOnPad){
          $scope.signalDisplayOnPad = false;
         }

    if("0" == obj.SignalDisplayOnPhone){
          $scope.signalDisplayOnPhone = false;
         }
    if("0" == obj.SignalDisplayOnTv){
          $scope.signalDisplayOnTv = false;
         }

     $scope.contact = obj;
      });
  }
//如果infoId不为空，查询详情：结束




  //表单提交开始
$scope.processForm= function (){
  


 //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"signal_info";
var formData =  $scope.contact;

  //1.参数处理
    formData.AddTime = getNowDBFormatDate();
    formData.UpdateTime = getNowDBFormatDate();
    formData.AdderId = 1;
    formData.AdderName = '1';
    formData.UpdaterId = 1;
    formData.UpdaterName = '1';
    formData.SignalUuid='';
    
    // formData.VideoBitRate = number(formData.VideoBitRate);
    // formData.VideoWidth = number(formData.VideoWidth);
    // formData.VideoHeight = number(formData.VideoHeight);
    // formData.AudioSamplingRate = number(formData.AudioSamplingRate);
    // formData.AudioBitRate = number(formData.AudioBitRate);
   
    formData.SignalEnable = '1';
    formData.SgnalDisplayOnPc = '1';
    formData.SignalDisplayOnPad = '1';
    formData.SignalDisplayOnPhone = '1';
    formData.SignalDisplayOnTv = '1';

    formData.VideoFrameRate = formData.VideoFrameRate+'';

    if(false == $scope.signalEnable){
          formData.SignalEnable = '0';
         }
    if(false == $scope.signalDisplayOnPc){
          formData.SgnalDisplayOnPc = '0';
         }
    if(false == $scope.signalDisplayOnPad){
          formData.SignalDisplayOnPad = '0';
         }

    if(false == $scope.signalDisplayOnPhone){
          formData.SignalDisplayOnPhone = '0';
         }
    if(false == $scope.signalDisplayOnTv){
          formData.SignalDisplayOnTv = '0';
         }

        console.log(JSON.stringify(formData));

  if("undefined"!=typeof(formData.Id)){

 $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.signal.signal');
                  }  
             }); 


  }else{

     $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.signal.signal');
                  }  
             }); 

  }



}
 //表单提交结束
 

});








// this is a lazy load controller, 
// so start with "app." to register this controller

app.filter('propsFilter', function() {
    return function(items, props) {
        var out = [];

        if (angular.isArray(items)) {
          items.forEach(function(item) {
            var itemMatches = false;

            var keys = Object.keys(props);
            for (var i = 0; i < keys.length; i++) {
              var prop = keys[i];
              var text = props[prop].toLowerCase();
              if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                itemMatches = true;
                break;
              }
            }

            if (itemMatches) {
              out.push(item);
            }
          });
        } else {
          // Let the output be the input untouched
          out = items;
        }

        return out;
    };
})







//选择类型下拉框
app.controller('SelectCtrl', function($scope, $http, $stateParams,$timeout) {



        $scope.disabled = undefined;
        $scope.searchEnabled = undefined;

        $scope.enable = function() {
        $scope.disabled = false;
        };

        $scope.disable = function() {
        $scope.disabled = true;
        };

        $scope.enableSearch = function() {
        $scope.searchEnabled = true;
        }

        $scope.disableSearch = function() {
        $scope.searchEnabled = false;
        }

        $scope.clear = function() {
        $scope.person.selected = undefined;
        $scope.address.selected = undefined;
        $scope.country.selected = undefined;
        };


        $scope.personAsync = {selected : "wladimir@email.com"};
        $scope.peopleAsync = [];


        $scope.counter = 0;
        $scope.someFunction = function (item, model){
        $scope.counter++;
        $scope.eventResult = {item: item, model: model};
        };

        $scope.removed = function (item, model) {
        $scope.lastRemoved = {
            item: item,
            model: model
        };
        };

        $scope.person = {};

        var infoUrl = API_URL+"stream_class?query=delflag:0";

        var formData =  MY_ASYNC_AJAX(infoUrl);
        $scope.people = formData;
        $scope.multipleDemo = {};
        $scope.multipleDemo.colors = ['Blue','Red'];

        //已经存在的
        var infoId = $stateParams.infoId;
         $scope.multipleDemo.selectedPeopleWithGroupBy = [];

         if(''!=infoId){
            var classUrl = API_URL+"r_signal_2_class?query=delflag:0,StreamId:"+infoId;
            var classList = MY_ASYNC_AJAX(classUrl);
             console.log('获取classList：'+classList);
          if(null !=  classList){
            for(var i= 0;i<classList.length;i++){
                     var infoClassUrl = API_URL+"stream_class?query=delflag:0,Id:"+classList[i].ClassId;
                     var infoClass = MY_ASYNC_AJAX(infoClassUrl)[0];
                        for(var j=0;j<formData.length;j++){
                        if($scope.people[j].Id == infoClass.Id){
                          $scope.multipleDemo.selectedPeopleWithGroupBy.push($scope.people[j]);
                          break;
                        }
                     }
                      
            }
            }
        }



      
});


</script>
<!--angularjs-->










